package demo.mvc.models
{
	import demo.mvc.Notifications;
	import demo.mvc.models.vo.VRole;
	
	import com.gamefx.mvc.Model;
	
	public class AccountModel extends Model
	{
		
		public var currentRole:VRole;
		
		
		public function AccountModel(modelName:String=null, data:Object=null)
		{
			super(modelName, data);
		}
		
		public function login(username:String, password:String):void
		{
			//远程验证
			//remote.send("Login", onLoginResult, username, password);
			
			//或者本地验证
			if (username == "test" && password == "1234")
			{
				loginResult(0);
			}
			else
			{
				loginResult(1);
			}
			
			
			function loginResult(data:Object):void
			{
				if (data == 0)
				{
					currentRole = new VRole();
					currentRole.name = username;
					currentRole.attack = 100;
					currentRole.defense = 100;
				}
				
				sendNotification(Notifications.MSG_ACCOUNT_LOGIN, data);
			}
		}
		
		public function logout():void
		{
			//TODO:通知远程
			//...
			
			logoutResult(0);
			
			function logoutResult(data:Object):void
			{
				sendNotification(Notifications.MSG_ACCOUNT_LOGOUT, data);
			}
		}
	}
}